﻿using HarmonyLib;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SuperMe
{
    class SuperMePatch_TradeShip
    {
        [HarmonyPatch(typeof(StorytellerComp_OnOffCycle))]
        [HarmonyPatch("MakeIntervalIncidents")]
        public class Patch_StorytellerComp_OnOffCycle_MakeIntervalIncidents
        {
            private static IncidentDef CatchIncident;
            private static StorytellerCompProperties_OnOffCycle CatchProps;

            [HarmonyPrefix]
            private static void MyPrefix(StorytellerComp_OnOffCycle __instance)
            {
                StorytellerCompProperties_OnOffCycle Props = __instance.props as StorytellerCompProperties_OnOffCycle;
                if (Props != null && Props.incident!=null)
                {
                    if (Props.incident.defName == IncidentDefOf.OrbitalTraderArrival.defName)
                    {
                        if (CatchIncident == null)
                        {
                            CatchIncident = Props.incident;
                            CatchProps = Props;
                            SuperMeDef.Log("Catch Incident :" + CatchIncident.defName + " Comp:" + __instance.ToString());
                            // Modify Props
                            Props.onDays = 15;
                            Props.offDays = 1;
                        }
                    }
                    if (Props.incident.defName == IncidentDefOf.TraderCaravanArrival.defName)
                    {
                        if (CatchIncident == null)
                        {
                            CatchIncident = Props.incident;
                            CatchProps = Props;
                            SuperMeDef.Log("Catch Incident :" + CatchIncident.defName + " Comp:" + __instance.ToString());
                            // Modify Props
                            Props.onDays = 15;
                            Props.offDays = 1;
                        }
                    }
                }
            }
        }
    }
}
